<?php

require_once BaseUtil::getModulePath ( "base" ) . '/controllers/BaseController.php';
require_once BaseUtil::getModulePath ( "cms" ) . '/services/FeaturePageService.php';
require_once BaseUtil::getModulePath ( "cms" ) . '/forms/FeaturePageForm.php';

class Cms_FeaturepageController extends BaseController {
	
	public function init() {
		parent::init();
	}
	
	public function indexAction() {
		$featurepageService=new FeaturepageService();
		$page=$featurepageService->getPages($this->view,$_POST);
		$this->view->page=$page;
	}
	
	public function addAction() {
		$featurepageForm=new FeaturepageForm();
		$this->view->form=$featurepageForm;
	}
	
	public function subaddAction() {
		$featurepageForm=new FeaturepageForm();
		$featurepageService=new FeaturePageService();
		if(!$featurepageForm->isValid($_POST)){
			$this->view->form=$featurepageForm;
			return $this->render('add');
		}
		$featurepageService->addPage($featurepageForm);
		$this->_redirect('/cms/featurepage');
	}
	
	public function editAction() {
        $pageid=$this->_getParam('id');
        $featurepageSerivce=new FeaturePageService();
        $page=$featurepageSerivce->getPageById($pageid);
        $featurepageForm=new FeaturepageForm(true);
        $featurepageForm->getElement("id")->setValue($page['id']);
        $featurepageForm->getElement("url")->setValue($page['url']);
        $featurepageForm->getElement("css")->setValue($page['css']);
        $featurepageForm->getElement("javascript")->setValue($page['javascript']);
        $featurepageForm->getElement("html")->setValue($page['html']);
        $this->view->form=$featurepageForm;
        $this->view->id=$pageid;
	}
	
	public function subeditAction() {
		$id = HttpUtil::getPostString ("id");
		$featurepageForm=new FeaturepageForm(true,$id);
		$featurepageService=new FeaturePageService();
		if(!$featurepageForm->isValid($_POST)){
			$this->view->form=$featurepageForm;
			return $this->render('edit');
		}
		$featurepageService->editPage($featurepageForm);
		$this->_redirect('/cms/featurepage');
	}
	
    public function deletesomeAction() {
        $idsStr=HttpUtil::getPostValue("selectIds");
        $ids=explode(",",$idsStr);
        $featurepageService=new FeaturePageService();
        $featurepageService->deletePage($ids);
        $this->_redirector->gotoUrl('/cms/featurepage');
    }
	
	public function deleteAction() {
		$id=$this->_getParam('id');
		$featurepageService=new FeaturePageService();
		$featurepageService->delete($id);
		$this->_redirector->gotoUrl('/cms/featurepage');
		
	}
	
	

}
